*
* This file contains Stata replication code for Barriers to Entry: Who Builds Fortified Boundaries and Why? 
* International Security 40.1, 2015. The results were generate in a Windows version of Stata 13.1.
*


*
* Table 2, comparing builders and targets
*
summ bgdppc2000 tgdppc2000 if wallsince90==1
summ bfree2000 tfree2000 if wallsince90==1 
summ bpopbpl2005 tpopbpl2005 if wallsince90==1
tab brelig2000 if wallsince90==1
tab trelig2000 if wallsince90==1
summ bcumter2000 tcumter2000 if wallsince90==1
count if wallsince90==1 & trelig2000==1 & brelig2000==6 	/* 17 of 29 Muslim targets have Muslim builders */ 
*
*
* Table 3, comparing dyads with walls to dyads without walls
*
by wallsince90, sort: summ dfree2000 dispute1995 dgdppc2000 ctattfromto2000 totcumter2000 dpopbpl2005 if edyad==0
by wallsince90, sort: summ tmigrant2005 if edyad==0 & target~="Afghanistan"
*
*
* Logit analyses--Appendix 1
*
capture drop sample1
logit wallsince90 trelig2000x10 dgdppc00div1000 dispute1995 lnbgdpperbdrl2000  dfree2000  trend2000b  if edyad==0, robust cluster(target)
gen sample1=e(sample)
estimates store m1
*
capture drop sample2
logit wallsince90 trelig2000x10 dgdppc00div1000 dispute1995 lnbgdpperbdrl2000  dfree2000 tmigrant2005  ctattfromto2000  if (edyad==0 & target~="Afghanistan"), robust cluster(target)
gen sample2=e(sample)
estimates store m2
*
capture drop sample3
logit wallsince90 trelig2000x10 dgdppc00div1000 dispute1995 lnbgdpperbdrl2000  dfree2000 tpopbpl2005  bcumter2000  if edyad==0, robust cluster(target)
gen sample3=e(sample)
estimates store m3
*
* Figure 2. (Note: uses the coefplot package. See the paper for the citation.)
*
estimates restore m1
coefplot m1, scheme(s1mono) drop(_cons) xline(0) xtitle("coefficient, model 1") coeflabel(dispute1995="dispute in 1995?" trelig2000x10="Is target Muslim?" ///
                                         lnbgdpperbdrl2000="capability" dgdppc00div1000="builder-target GDPPC" ///
										 dfree2000="freedom difference"  ///
										 trend2000b="terror trend to 2000", wrap(21)) ///
		  ciopts(recast(rcap)) mlabels(trelig2000x10 = 1 "+" dgdppc00div1000 = 1 "+") ///
		  groups(trelig2000x10 dgdppc00div1000 dispute1995 lnbgdpperbdrl2000 dfree2000 = "common factors" ///
		         trend2000b = "unique factors", wrap(10)) grid(none) color(black) ylabel(,tstyle(major_notick))
graph save fm1, replace
*
estimates restore m2
coefplot m2, scheme(s1mono) drop(_cons) xline(0) xtitle("coefficient, model 2") coeflabel(dispute1995="dispute in 1995?" trelig2000x10="Is target Muslim?" ///
                                         lnbgdpperbdrl2000="capability" dgdppc00div1000="builder-target GDPPC" ///
										 dfree2000="freedom difference" tmigrant2005="target migrants, 2005" ///
										 ctattfromto2000="target terror on builder, to 2000", wrap(21)) ///
		  ciopts(recast(rcap)) mlabels(trelig2000x10 = 1 "+" dgdppc00div1000 = 1 "+") ///
		  groups(trelig2000x10 dgdppc00div1000 dispute1995 lnbgdpperbdrl2000 dfree2000 = "common factors" ///
		         tmigrant2005 ctattfromto2000= "unique factors", wrap(10)) grid(none) color(black) ylabel(,tstyle(major_notick))
graph save fm2, replace
*
estimates restore m3
coefplot m3, scheme(s1mono) drop(_cons) xline(0) xtitle("coefficient, model 3") coeflabel(dispute1995="dispute in 1995?" trelig2000x10="Is target Muslim?" ///
                                         lnbgdpperbdrl2000="capability" dgdppc00div1000="builder-target GDPPC" ///
										 dfree2000="freedom difference"  tpopbpl2005="target poverty, 2005" ///
										 bcumter2000="terror on builder, to 2000", wrap(21)) ///
		  ciopts(recast(rcap)) mlabels(trelig2000x10 = 1 "+" dgdppc00div1000 = 1 "+") ///
		  groups(trelig2000x10 dgdppc00div1000 dispute1995 lnbgdpperbdrl2000 dfree2000 = "common factors" ///
		         tpopbpl2005 bcumter2000= "unique factors", wrap(10)) grid(none) color(black) ylabel(,tstyle(major_notick))
graph save fm3, replace
*
gr combine "fm1.gph" "fm2.gph" "fm3.gph", scheme(s1mono) 
graph save ffig2, replace
doitashi
*

*
* Compute proportion of Muslim on Muslim barriers
*
count if wallsince90==1 & trelig2000==1							/* How many with Muslim targets */
count if wallsince90==1 & trelig2000==1 & builder~="Israel"		/* Exclude Israel barriers */
count if wallsince90==1 & trelig2000==1 & brelig2000==6 		/* How many ALSO have Muslim builders */
*
* Run margins under conditions where a country might be least likely to want to build a barrier:
* No land dispute, no difference in freedom, least money to build barrier, no terror trend betw 1990 and 2000
*
logit wallsince90 i.trelig2000x10 dgdppc00div1000 dispute1995 lnbgdpperbdrl2000  dfree2000  trend2000b  if edyad==0, robust cluster(target)
margins i.trelig2000x10, at(dgdppc00div1000=(-12 (4) 12)) at(dispute1995=0 dfree2000=0 lnbgdpperbdrl2000=12 trend2000b=0)  vsquish
*
* title(Probability of a Barrier by Target Religion and Differences in GDPPC)
*
marginsplot, scheme(lean1) xtitle(difference in GDPPC between builder and target in $ 1000s) ytitle(probability of a barrier) /// 
             legend(off) title(" ") ylabel(0 "0" .2 "0.2" .4 "0.4" .6 "0.6", angle(horizontal))  /// 
			 text(0.17 4 "muslim target", place(w) color(black)) text(0.03 8 "non-Muslim target", place(w) color(black))
